﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using UCenter.Core.Model;

namespace UCenter.Models {
    [Table(Name = "dbo.Profile")]
    public class Profile : EntityBase {
        #region Private Fields

        private int _Id;

        private string _trueName;

        private string _nickName;

        private string _gender;

        private DateTime? _birthday;

        private string _hometown;

        private string _QQ;

        private string _MSN;

        private string _phoneNumber;

        private string _website;

        private string _status;

        private DateTime? _lastUpdateStatusTime;

        private string _userLogo;

        private EntityRef<User> _user;


        #endregion

        #region Constructor

        public Profile() {
            this._user = default(EntityRef<User>);
        }

        #endregion

        #region Public Properties

        [Column(Name = "ID", Storage = "_Id", DbType = "Int NOT NULL", IsPrimaryKey = true)]
        public int ID {
            get {
                return this._Id;
            }
            set {
                if (this._Id != value) {
                    if (this._user.HasLoadedOrAssignedValue) {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }

                    this.SendPropertyChanging("ID");
                    this._Id = value;
                    this.SendPropertyChanged("ID", value);
                }
            }
        }

        [Column(Name = "TrueName", Storage = "_trueName", DbType = "VarChar(64) NOT NULL", CanBeNull = false)]
        public string TrueName {
            get {
                return this._trueName;
            }
            set {
                if (this._trueName != value) {
                    this.SendPropertyChanging("TrueName");
                    this._trueName = value;
                    this.SendPropertyChanged("TrueName", value);
                }
            }
        }

        [Column(Name = "NickName", Storage = "_nickName", DbType = "VarChar(64)")]
        public string NickName {
            get {
                return this._nickName;
            }
            set {
                if (this._nickName != value) {
                    this.SendPropertyChanging("NickName");
                    this._nickName = value;
                    this.SendPropertyChanged("NickName", value);
                }
            }
        }

        [Column(Name = "Gender", Storage = "_gender", DbType = "VarChar(8)")]
        public string Gender {
            get {
                return this._gender;
            }
            set {
                if (this._gender != value) {
                    this.SendPropertyChanging("Gender");
                    this._gender = value;
                    this.SendPropertyChanged("Gender", value);
                }
            }
        }

        [Column(Name = "Birthday", Storage = "_birthday", DbType = "DateTime")]
        public DateTime? Birthday {
            get {
                return this._birthday;
            }
            set {
                if (this._birthday != value) {
                    this.SendPropertyChanging("Birthday");
                    this._birthday = value;
                    this.SendPropertyChanged("Birthday", value);
                }
            }
        }

        [Column(Name = "Hometown", Storage = "_hometown", DbType = "VarChar(128)")]
        public string Hometown {
            get {
                return this._hometown;
            }
            set {
                if (this._hometown != value) {
                    this.SendPropertyChanging("Hometown");
                    this._hometown = value;
                    this.SendPropertyChanged("Hometown", value);
                }
            }
        }

        [Column(Name = "QQ", Storage = "_QQ", DbType = "VarChar(128)")]
        public string QQ {
            get {
                return this._QQ;
            }
            set {
                if (this._QQ != value) {
                    this.SendPropertyChanging("QQ");
                    this._QQ = value;
                    this.SendPropertyChanged("QQ", value);
                }
            }
        }

        [Column(Name = "MSN", Storage = "_MSN", DbType = "VarChar(128)")]
        public string MSN {
            get {
                return this._MSN;
            }
            set {
                if (this._MSN != value) {
                    this.SendPropertyChanging("MSN");
                    this._MSN = value;
                    this.SendPropertyChanged("MSN", value);
                }
            }
        }

        [Column(Name = "PhoneNumber", Storage = "_phoneNumber", DbType = "VarChar(128)")]
        public string PhoneNumber {
            get {
                return this._phoneNumber;
            }
            set {
                if (this._phoneNumber != value) {
                    this.SendPropertyChanging("PhoneNumber");
                    this._phoneNumber = value;
                    this.SendPropertyChanged("PhoneNumber", value);
                }
            }
        }

        [Column(Name = "Website", Storage = "_website", DbType = "VarChar(128)")]
        public string Website {
            get {
                return this._website;
            }
            set {
                if (this._website != value) {
                    this.SendPropertyChanging("Website");
                    this._website = value;
                    this.SendPropertyChanged("Website", value);
                }
            }
        }

        [Column(Name = "State", Storage = "_status", DbType = "VarChar(512)", UpdateCheck = UpdateCheck.Never)]
        public string State {
            get {
                return this._status;
            }
            set {
                if (this._status != value) {
                    this.SendPropertyChanging("Status");
                    this._status = value;
                    this.SendPropertyChanged("Status", value);
                }
            }
        }

        [Column(Name = "StateRefreshTime", Storage = "_lastUpdateStatusTime", DbType = "DateTime", UpdateCheck = UpdateCheck.Never)]
        public DateTime? StateRefreshTime {
            get {
                return this._lastUpdateStatusTime;
            }
            set {
                if (this._lastUpdateStatusTime != value) {
                    this.SendPropertyChanging("UpdateStatusTime");
                    this._lastUpdateStatusTime = value;
                    this.SendPropertyChanged("UpdateStatusTime", value);
                }
            }
        }
        [Column(Name = "Avatar", Storage = "_userLogo", DbType = "Varchar(512)")]
        public string Avatar {
            get {
                return this._userLogo;
            }
            set {
                if (this._userLogo != value) {
                    this.SendPropertyChanging("UserLogo");
                    this._userLogo = value;
                    this.SendPropertyChanged("UserLogo", value);
                }
            }
        }
        [Association(Name = "User_Profile", Storage = "_user", ThisKey = "ID", IsForeignKey = true)]
        public User User {
            get {
                return this._user.Entity;
            }
            set {
                User previousValue = this._user.Entity;
                if (((previousValue != value)
                            || (this._user.HasLoadedOrAssignedValue == false))) {
                    if ((previousValue != null)) {
                        this._user.Entity = null;
                        previousValue.Profile = null;
                    }
                    this._user.Entity = value;
                    if ((value != null)) {
                        value.Profile = this;
                        this._Id = value.ID;
                    }
                    else {
                        this._Id = default(int);
                    }
                }
            }
        }

        #endregion
    }
}
